document.addEventListener('visibilitychange', function () {
  if (document.visibilityState === 'hidden') {
    //隐藏
  } else {
    //显示
  }
})